<?php
namespace Home\Controller;
use Home\Model\DeviceListModel;
use Home\Model\DeviceStainfoModel;
use Home\Model\PassbyPushModel;
use Think\Controller;
class AsidemonitorController extends BaseController  {
    public function index(){
        $this->assign('title','旁路监听');
        $this->assign('currentname','asidemonitor');
        $this->display();
    }

    public function getStamac(){
        if(IS_POST){
            $model=new DeviceStainfoModel();
            $list=$model->getStaByMAC(I('stamac'));
            $this->ajaxReturn($list);
        }
    }

    public function getPass(){
        if(IS_POST){
            $model=new PassbyPushModel();
            $list=$model->getPassbyPush('self');
            $this->ajaxReturn($list);
        }
    }

    public function setPass(){
        if(IS_POST){
            $data=$_POST;
            $data['pushtime']=date('Y-m-d H:i:s',time());
            $data['status']=0; //成功
            $data['actionstatus']='start';
            $deviceserialno=$data['deviceserialno'];

            //先关闭伪装
            session('wzwifi', null);
            ScanwifiController::setstatus('stop','wz', '',  '', '', '',  '', 0, '', 2, 0, 0);


            $url=$_SESSION['cardinfo'][self::$cardtype_wz]['cardip'] .
                C('LUCI_WIFISCAN_URL') . 'WZWifi/stop////';
            $retdata = http_post_json($url, null);
            sleep(1);



            //调用下发接口WifiBypass
            $url=$_SESSION['cardinfo'][self::$cardtype_wz]['cardip'] . C('LUCI_WIFISCAN_URL') . 'WifiBypass/start'
            .'/'.I('post.mod1')
            .'/'.I('post.channel1')
            .'/'.I('post.ssid1')
            .'/'.I('post.encrypt1');
            $ret = http_post_json($url, null);
            $ret=json_decode($ret);

            if(I('post.ssid2')!=''){
                sleep(1);
                $url=$_SESSION['cardinfo'][self::$cardtype_wz]['cardip'] . C('LUCI_WIFISCAN_URL') . 'WifiBypass/start'
                    .'/'.I('post.mod2')
                    .'/'.I('post.channel2')
                    .'/'.I('post.ssid2')
                    .'/'.I('post.encrypt2');
                $ret = http_post_json($url, null);
            }else{
                $data['mod2']='';
            }
            if(I('post.ssid3')!=''){
                sleep(1);
                $url=$_SESSION['cardinfo'][self::$cardtype_wz]['cardip'] . C('LUCI_WIFISCAN_URL') . 'WifiBypass/start'
                    .'/'.I('post.mod3')
                    .'/'.I('post.channel3')
                    .'/'.I('post.ssid3')
                    .'/'.I('post.encrypt3');
                $ret = http_post_json($url, null);
            }else{
                $data['mod3']='';
            }



            $model=new PassbyPushModel();
            $rets=$model->getPassbyPush('self');
            if(!$rets){
                $list=$model->addPassbyPush($data);
            }else{
                $list=$model->modPassbyPush($data);
            }


            $this->ajaxReturn( array('data'=>$list,'status'=>true, 'info'=>''),'json');
        }
    }

    public function closePass(){
        if(IS_POST){
            $data=$_POST;
            $data['pushtime']=date('Y-m-d H:i:s',time());
            $data['actionstatus']='stop';
            $deviceserialno=$data['deviceserialno'];

            //调用下发接口WifiBypass
            //function WifiBypass_Act(action,mod,chan,essid,pass)
            $url=$_SESSION['cardinfo'][self::$cardtype_wz]['cardip'] . C('LUCI_WIFISCAN_URL') . 'WifiBypass/stop'
                .'/'.''
                .'/'.''
                .'/'.''
                .'/'.'';
            $ret = http_post_json($url, null);



            $model=new PassbyPushModel();
            $list=$model->closePassbyPush('self');

            $this->ajaxReturn( array('data'=>$list,'status'=>true, 'info'=>''),'json');
        }
    }
}